package cn.hrlly.tao2shou.presenter;

import android.content.Context;

import cn.hrlly.tao2shou.biz.LoginBiz;
import cn.hrlly.tao2shou.biz.LoginBizImpl;
import cn.hrlly.tao2shou.domain.User;
import cn.hrlly.tao2shou.listener.OnLoginListener;
import cn.hrlly.tao2shou.view.view_interface.LoginView;

/**
 * login的逻辑处理
 * 获取到了后台返回的数据，对view进行操作
 * User: gengliang
 * Date: 2016-01-22
 * Time: 08:53
 */

public class LoginPresenterImpl implements OnLoginListener,LoginPresenter {

    private LoginBiz loginBiz;
    private LoginView loginView;

    public LoginPresenterImpl(LoginView loginView,Context context){
        this.loginView=loginView;
        loginBiz=new LoginBizImpl(this,context);
    }

    @Override
    public void login() {
        User user=new User();
        user.setPhoneNumber(loginView.getPhoneNumber());
        user.setPassword(loginView.getPassword());
        user.setLongditude(loginView.getLongitude());
        user.setLantitude(loginView.getLantitude());
        loginBiz.login(user);
    }

    @Override
    public void closeDataBase() {
        loginBiz.closeDataBase();
    }

    @Override
    public void loginSuccess(final User user) {
        loginView.startActivity();

        //将user信息保存到数据库,io线程中
        loginBiz.saveUserInfo(user);
    }

    @Override
    public void loginFail(String errorMessage) {
        loginView.showMessage(errorMessage);
    }

    @Override
    public void loginFail(int errorMessage) {
        loginView.showMessage(errorMessage);
    }
}
